package com.lm.ledger.action;

import java.util.ArrayList;
import java.util.List;

import com.lm.ledger.exception.LedgerException;
import com.lm.ledger.service.TransactionService;
import com.lm.ledger.service.TransactionServiceImp;
import com.lm.ledger.utill.Account;
import com.opensymphony.xwork2.ActionSupport;

public class EditTransaction extends TrxAction{

	private List accounts;
	private Account account;
	TransactionService service = new TransactionServiceImp();
	
	public String getAllTrx(){
		System.out.println("getAllTrx called--------------");
		//try {
			setLocations(service.getLocations(getUser().getUserId()));
		//} catch (LedgerException e) {
	//		e.printStackTrace();
	//	}
		accounts = service.getAllTrxs(getUser().getUserId());
   	 return "success";
   }
	
	public String saveEditTrx(){
		System.out.println("saveEditTrx called--------------");
		service.updateTrx(getAccountDetail());
		accounts = service.searchAllUserTrx(getUser().getUserId());
		return "success";
   }
	
	public String editTrx(){
		System.out.println("editTrx called----aaa----------");
		System.out.println("form id ---- "+getFormId());
				
		Account acc = service.getAccountForFormId(getFormId());		
		setValues(acc);
   	 return "success";
   }
	
	public String searchEditTrx(){
		System.out.println("searchEditTrx called----aaa----------");
		System.out.println("form id "+getFormId());
		System.out.println("loc id   "+getLocId());
		System.out.println("trx date   "+getTxDate());
		System.out.println("trx type  "+getTxTye());
		System.out.println("status  "+getStatus());
		
			setLocations(service.getLocations(getUser().getUserId()));
		
		System.out.println("locations "+getLocations().size());
		setAccounts(service.searchList(getAccountDetail(), getUser().getUserId(), "edit"));
		//setValues(getAccountDetail());
   	 return SUCCESS;
   }
	public String rejectTrx(){
		System.out.println("rejectTrx called----aaa----------");
		System.out.println("form id--- "+getFormId());
		service.rejectTrx(getFormId());
   	 return SUCCESS;
   }
	
	public List getAccounts() {
		return accounts;
	}
	public void setAccounts(List accounts) {
		this.accounts = accounts;
	}
	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
	public String getTrxToApprove(){
		accounts = service.searchApproveTrx(getUser().getUserId());
   	 return SUCCESS;
   
   }
}
